
//模块主窗口
var Setlte =  Setlte||{};
JieSuanAllPanel = Ext.extend(Ext.Panel,{
	 closable: true,
   	 autoScroll:true,
   	 width:'100%',
   	 height:700,
initComponent : function() {
			var thisPanel = this;
   			this.tbar =  this.buildBbar() ;
   			
   			var dataStore = new Ext.data.JsonStore({
					url:"Settle_getTrendsChartReport.action",
					root: 'root',
			        idProperty: 'id',
			        fields: [
			           'CYCLE_ID','JSFEE','FEE','FEEJS','COUNTS'
			        ]
				});

   			var gd = new JieSuanAllDataPanel() ;
   			var feeChart = new Setlte.UserFeeChar({'dataStore':dataStore});
   			this.items = [new QueryStatSetlteFeeAllUserForm({
					thisGrid:gd,
					chartPanel:feeChart
					
				}),feeChart,gd] ;
			JieSuanAllPanel.superclass.initComponent.call(this);
   	},
   	  statSetlteFeeUser : function(btn) {
   		var cycleId = btn.ownerCt.ownerCt.cycleId.getValue();
   		var gp = btn.ownerCt.ownerCt.items.get(1) ;

   	}
   	,querySetlteFeeUser : function(btn) {
   		 var tform = btn.ownerCt.ownerCt.formPanel;
   	     tform.show();
   	},exportData:function(btn) {
   		var gp = btn.ownerCt.ownerCt.items.get(2) ;
   			var baseParams = gp.getStore().baseParams;
   		var ul = Ext.urlEncode(baseParams);
   		var st = gp.getStore();
   		Ext.MessageBox.confirm("确认", "确定导出?", function(btn) {
		if (btn == "yes") {
			window.location.href ="Settle_exportTfFSettleUserAllsToExcel.action?limit="+st.totalLength;
		
		}
		});
   		
   	}
   	
,buildBbar: function() {
   		return [
   		{
   				text : "显示查询",
   				iconCls: 'ico-dot-search-open',
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(2);
   					var c = m.items.get(1);
   					var a = m.items.get(0);
   					a.setHeight(70);
   					a.searchBtn = btn;
   					if(a.collapsed) {
   						var h1 = m.getHeight()-c.getHeight()-m.tbar.dom.clientHeight-a.getHeight();
   						a.expand(true);
   						g.setHeight(h1-70);
   						btn.setText("隐藏查询");
   						btn.setIconClass("ico-dot-search-hidden");
   					} else {
   						a.collapse(true);
   						g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
   						btn.setText("显示查询");
   						btn.setIconClass("ico-dot-search-open");
   					}
   				}
   			}
//   			{
//   				text : "按条件查询",
//   				handler :this.querySetlteFeeUser,
//   				iconCls: 'ico-dot-search'
//   			}
   			,'-',{
   				text : "数据导出",
   				handler :this.exportData,
   				iconCls: 'ico-dot-report'
   			} 
   			,'-',{
   				text : "隐藏用户费用趋势图",
   				handler :this.statSetlteFeeUser,
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(1);
   					if(g.collapsed) {
   						g.expand();
   						btn.setText("隐藏用户费用趋势图");
   						btn.setIconClass("ico-dot-chart-del");
   					} else {
   						g.collapse();
   						btn.setText("显示用户费用趋势图");
   						btn.setIconClass("ico-dot-chart-add");
   					}
   				},
   				iconCls: 'ico-dot-chart-del'
   			}
   			,'->',{
                    	text:'操作说明'					
                    	,iconCls:'ico-dot-question'
                    	,handler:function(){
                    		SM.Explanation.showExplanation(37);
                    	}
                    }
                   ];
   	}
  	
});


JieSuanAllDataPanel = Ext.extend(Ext.grid.EditorGridPanel,{
	title : '结算综合列表',
	header: false,
	loadMask:{msg:'加载中...'},
	enableDragDrop: false,
	height: 560,
	columnLines:true,
	allowHeaderWrap:true,
	allowWrap:false,
//	viewConfig :{
//        //forceFit: true
//    },
	initComponent : function() {
       	var thisGrid = this;
       	this.recordStart = 1 ;
    	var settleCmSelectionModel = new Ext.grid.CheckboxSelectionModel({
                                dataIndex: "uid",
                sortable: false,
                singleSelect:false,
                width:20
		});
		var settleUserNew = new　Ext.grid.RowNumberer({
		　　header　:　"序号",
		　　width　:　35
		});
		this.columns　=　[settleCmSelectionModel,settleUserNew,{
		        header:'账期',
				sortable:true,
				dataIndex:"CYCLE_ID",
				width:60
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			}

		    ,{
				header:'归属地市',
				sortable:true,
				dataIndex:"EPARCHY_CODE",
				width:60
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},{
		        header:'网别',
				sortable:true,
				dataIndex:"NET_TYPE_CODE",
				width:100
				,headerAlign :"center"
				,align :"left"
				,allowHeaderWrap:true
				,allowWrap:false
			},　
		    {
				header:'用户数(户)',
				sortable:true,
				dataIndex:"COUNTS",
				width:100,
				renderer:this.ToFixed
				,headerAlign :"center"
				,align :"right"
				,allowHeaderWrap:true
				,allowWrap:false
			},　
		    {
				header:'结算总费用(元)',
				sortable:true,
				dataIndex:"FEEJS",
				width:100,
				renderer:this.ToFixed
				,headerAlign :"center"
				,align :"right"
				,allowHeaderWrap:true
				,allowWrap:false
			},　
		    {
				header:'应收总费用(元)',
				sortable:true,
				dataIndex:"FEE",
				width:100,
				renderer:this.ToFixed
				,headerAlign :"center"
				,align :"right"
				,allowHeaderWrap:true
				,allowWrap:false
			},　
		    {
				header:'结算净流失总费用(元)',
				sortable:true,
				dataIndex:"JSFEE",
				width:100,
				renderer:this.ToFixed
				,headerAlign :"center"
				,align :"right"
				,allowHeaderWrap:true
				,allowWrap:false
			}
		] ;
		var dataStore = new Ext.data.JsonStore({
			url : 'Settle_TfFSettleUserAll.action',
			root: 'root',
	        totalProperty: 'totalProperty',
	        idProperty: 'id',
	        fields: [
				'CYCLE_ID','EPARCHY_CODE','NET_TYPE_CODE','COUNTS','COUNTS','FEEJS','FEE','JSFEE'
			]});
	    dataStore.baseParams ={'settleUser':null};
		this.store = dataStore;
		this.sm = settleCmSelectionModel;
	    this.mk=new Ext.LoadMask(Ext.getBody(),{
							msg:'正在努力为您加载数据，请稍候...'
				});
		this.bbar = new Ext.PagingToolbar({
			pageSize : 200,
			store : dataStore,
			displayInfo : true,
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录",
			listeners:{
				beforechange:function(pt,obj) {
					thisGrid.recordStart = obj.start+1 ;
				    
				}
			}
		});
		dataStore.load({
			params:{
				start:0,
				limit:200
			}
		});
	JieSuanAllDataPanel.superclass.initComponent.call(this);
	},listeners : {
   		'afterrender':function(com) {
//   			com.getStore().load({
//					params:{
//					start:0,
//					limit:200
//					}
//			});
   		}
   	}
});
//条件查询隐藏出现
QueryStatSetlteFeeAllUserForm = Ext.extend(Ext.form.FormPanel,{
	text:"表单",
	layout:"form",
	region : "center",
	labelAlign:"right",
	collapsible:true,
	collapsed:false,
	header:false,
	width:"100%",
	height:1,
	frame:true,
	layout:'table',
	layoutConfig:{
	tableAttrs: {
		align:'left'
	 },
	columns: 5
 	},
	initComponent: function(){
	this.items=[{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '归属地市',
							name : 'eparchy_code',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : areaCodeSelect,
							emptyText:"请选择",
							anchor:"90%",
							width:100
//							,listeners : {
//		 						"select": function(combo){
//								//	cityNameSelect.baseParams={'areaCode':combo.getValue()};
//									cityNameSelect.load();
//		 						}
//							}
						}]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期',
							name : 'cycleId',
							xtype : 'combo',
							editable : false,
							mode : 'local',
							triggerAction : 'all',
							store : getCyids(),//  [['0','请选择'],['201303','201303'],['201304','201304'],['201305','201305']],
							anchor:"90%",
							emptyText:"请选择",
							width:100
					    }]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '网别',
							name : 'netTypeCode',
							xtype : 'combo',
							editable : false,
							mode : 'local',
							emptyText:"请选择",
							triggerAction : 'all',
							store : [[null,'全部'],['10','2G用户'],['33','3G用户']],
							anchor:"90%",
							width:100
						}]}
		];
	  QueryStatSetlteFeeAllUserForm.superclass.initComponent.call(this);
	},
	buttonAlign :'center',
	minButtonWidth:60,
	buttons:[{
		text:"确定",
		handler : function(btn){
		    var thisForm = btn.ownerCt.ownerCt.getForm();
//		    var eparchy_code  = thisForm.findField('eparchy_code').getValue();
//		    var statDay = thisForm.findField('statDay').getValue();	 
//		    	statDay = statDay?statDay.format("Ymd"):"";	    
		    var nettypecode = thisForm.findField('netTypeCode').getValue();
			var eparchyCode = thisForm.findField('eparchy_code').getValue();
			var cycleId = thisForm.findField('cycleId').getValue();
			
		    var store = btn.ownerCt.ownerCt.thisGrid.getStore();
		    btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
		    store.baseParams = {

		    			'settleUser.netTypeCode':nettypecode,
		    		    'settleUser.cycleId':cycleId,
		    			'settleUser.eparchyCode':eparchyCode
			};

            store.load({params:{start:0, limit:200}});
		    
		   //this.ownerCt.ownerCt.ownerCt.hide();//隐藏弹出页面
		}
	}, {
		text : '重置',
		handler : function() {this.ownerCt.ownerCt.form.reset();}
	}, {
		text : '关闭',
		handler : function() {
		this.ownerCt.ownerCt.collapse(true);
			var m = this.ownerCt.ownerCt.ownerCt;
   			var g = m.items.get(2);
   			var c = m.itmes.get(1);
   			var a = m.items.get(0);
			g.setHeight(m.getHeight()-c.getHeught()-m.tbar.dom.clientHeight-1);
   			this.ownerCt.ownerCt.searchBtn.setText("显示查询");
   			this.ownerCt.ownerCt.searchBtn.setIconClass("ico-dot-search-open");
		}
	}]
});

Setlte.UserFeeChar = Ext.extend(Ext.Panel,{
	        width: "100%",
	        collapsible:true,
			collapsed:false,
			title:'每日用户费用趋势图',
	        height: 350,
	        initComponent: function(){
	        	var thisPanel = this;
		        var dataStore = this.dataStore;
				this.store = dataStore;
		        this.items = [{
		            xtype: 'linechart',
		            store: dataStore,
		            plugins:[new Ext.ux.plugin.VisibilityMode()],
		            yAxis: new Ext.chart.NumericAxis({  
			            title: '结算费用(元)'
			        })
			        ,tipRenderer : function(chart, record, index, series){
			        	if(series.yField=="JSFEE") {
			        		return series.displayName+"\n"+record.data['CYCLE_ID']+"\n"+Ext.util.Format.chMoney(series.data[index]['JSFEE'])+"元";
			        	}else if(series.yField=="COUNTS") {
			        		return series.displayName+"\n"+series.data[index]['CYCLE_ID']+"\n"+Ext.util.Format.chMoney(series.data[index]['COUNTS'])+"条";
			        	}else if(series.yField=="FEEJS") {
			        		return series.displayName+"\n"+series.data[index]['CYCLE_ID']+"\n"+Ext.util.Format.chMoney(series.data[index]['FEEJS'])+"元";
			        	}else if(series.yField=="FEE") {
			        		return series.displayName+"\n"+series.data[index]['CYCLE_ID']+"\n"+Ext.util.Format.chMoney(series.data[index]['FEE'])+"元";
			        	}
			        }
			        ,extraStyle: {
			        	xAxis: {  
			                labelRotation: -30//x轴标题旋转度数
			                ,majorGridLines: {size: 1, color: 0xdfe8f6}
			                ,majorTicks: {color: 0x69aBc8, length: 4},
                   			 minorTicks: {color: 0x69aBc8, length: 2}
			            },  
			            yAxis: {  
			                labelRotation: 0//y轴标题旋转度数  
			            	,titleRotation:-90
			            	,majorGridLines: {size: 1, color: 0xeeeeee}
//			           
			            } ,
			            legend:{
			            	display:'top'
			            }
			            ,visibility:false
			        }  
		            ,series: [
		            {
		                 type: 'line',
		            	yField: 'FEEJS',
		            	xField: 'CYCLE_ID',
		                displayName: '结算总费用(元)',
		                style: {
		                	color:0xFF0080,
		                	size:8
		                }
		            },
		            {
		                type: 'line',
		            	yField: 'JSFEE',
		            	xField: 'CYCLE_ID',
		                displayName: '结算净流失总费用(元)',
		                style: {
		                	color:0x800080,
		                	size:8
		                }
		            },{
		                type: 'line',
		            	yField: 'FEE',
		            	xField: 'CYCLE_ID',
		                displayName: '应收总费用(元)',
		                style: {
		                	color:0xffff00,
		                	size:8
		                }
		            },{
		                 type: 'line',
		            	yField: 'COUNTS',
		            	xField: 'CYCLE_ID',
		                displayName: '用户数(户)',
		                style: {
		                	
		                	size:8
		                }
		            }
		            ]
		        }];
		        Setlte.UserFeeChar.superclass.initComponent.call(this);
	        },listeners : {
   			'afterrender':function(com) {
   			com.store.load();
   				}
   	}
});